package com.haoshuang.zhouzhoubang.ui.page.order.assignment

import android.view.View
import com.chad.library.adapter4.BaseQuickAdapter
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ItemMemberListBinding
import com.haoshuang.zhouzhoubang.model.bean.RenWuBean
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.utils.view.load
import com.mufeng.libs.utils.view.visibleOrGone


/**
 *  成员列表适配器
 * @param data 列表数据
 * @param type 列表条目类型判定 0隐藏成员状态（默认隐藏） 1 显示成员状态
 * */
class MemberListAdapter(data: MutableList<RenWuBean.TeamMemberData>, val type: Int):
    BaseBindingQuickAdapter<RenWuBean.TeamMemberData, ItemMemberListBinding>(data) {

    override fun onBindViewHolder(
        holder: BaseBindingHolder,
        position: Int,
        item: RenWuBean.TeamMemberData?
    ) {
        if (item == null) return

        var choiceFlog = false
        val divider = holder.getView<View>(R.id.divider)    //分割线
        divider.visibleOrGone(holder.layoutPosition != items.size-1) // 如果当前数据的位置是最后一个隐藏分割线

        val flexboxLayoutManager1 = FlexboxLayoutManager(context)
        flexboxLayoutManager1.flexDirection = FlexDirection.ROW
        flexboxLayoutManager1.flexWrap = FlexWrap.WRAP   //按正常方向换行
        flexboxLayoutManager1.justifyContent = JustifyContent.FLEX_START //交叉轴的起点对齐。

        val binding = ItemMemberListBinding.bind(holder.itemView)
        binding.apply {
            tvName.text = item.nickname
            roundedImageView3.load(item.avatar, R.mipmap.rl)
            if (item.isCHeck==1){
                ivChoiceBox.setImageResource(R.mipmap.icon_pay_check_s)
            }else{
                ivChoiceBox.setImageResource(R.mipmap.icon_pay_check_n)
            }

            when(item.work_rest){
                "0" -> {  // 隐藏状态
                    tvStateBusy2.visibleOrGone(false)
                    //   tvStateLeisure.visibleOrGone(true)
                    when(item.work_status){
                        0 -> {  // 隐藏状态
                            tvStateBusy.visibleOrGone(false)
                            tvStateLeisure.visibleOrGone(true)
                        }
                        1 -> {  // 显示状态
                            tvStateBusy.visibleOrGone(true)
                            tvStateLeisure.visibleOrGone(false)
                        }
                    }
                }
                "1" -> {  // 显示状态
                    tvStateBusy2.visibleOrGone(true)
                    // tvStateLeisure.visibleOrGone(false)
                }
            }
            var   mrvSerciceAdapter = ServiceLabelAdapter(item.skill_name as MutableList<String>)
            recyclerView.layoutManager = flexboxLayoutManager1	// 给recycleview设置布局管理者
            recyclerView.adapter = mrvSerciceAdapter
            //  mrvSerciceAdapter.setList(item.skill_name)

        }
    }


}